package cate.common.table.call.sheet;

import cate.common.table.ESheet;
import cate.common.table.call.row.CallWeightRow;

import java.util.HashMap;
import java.util.Map;

public class CallWeightSheet extends ESheet<CallWeightRow> {
    public final Map<Integer, Map<Integer, CallWeightRow>> groupMap = new HashMap<>();

    /**
     * 当row创建完之后
     */
    @Override
    protected void onRowCreated(CallWeightRow row) {
        Map<Integer, CallWeightRow> list = groupMap.computeIfAbsent(row.group, k -> new HashMap<>());
        list.put(row.id, row);
    }

    @Override
    protected CallWeightRow buildRow() {
        return new CallWeightRow();
    }

    @Override
    public String getSheetName() {
        return "召唤概率";
    }

    public CallWeightRow getRowByHeroId(int group, int heroId) {
        Map<Integer, CallWeightRow> map = groupMap.get(group);
        if (map != null) {
            return map.values().stream().filter(e -> e.heroId == heroId).findAny().orElse(null);
        }
        return null;
    }

    public Map<Integer, CallWeightRow> getGroupRows(int group){
        return groupMap.getOrDefault(group, new HashMap<>());
    }
}
